package com.gzs.learn.payment.aspect;

import com.gzs.learn.common.AppCoordinate;
import com.gzs.learn.common.aspect.PerfBaseAspect;
import com.gzs.learn.payment.config.properties.PaymentProperties;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.stereotype.Component;

import static com.gzs.learn.payment.PaymentConstants.SYSTEM_PREFIX;

/**
 * 记录接口请求中的参数,类似于nginx/httpd中的access log功能
 *
 * @author guanzhisong
 */
@Component
@Aspect
@Slf4j
@RequiredArgsConstructor
public class PerformanceAspect extends PerfBaseAspect {
    private static final String DUBBO_POINTCUT = "within(" + SYSTEM_PREFIX + ".*.dubbo..*)";

    private final PaymentProperties paymentProperties;

    @Pointcut(REST_POINT_CUT + "||" + DUBBO_POINTCUT + "||" + ANNOTATION_PERFLOG)
    public void log4Perf() {
    }

    @Around("log4Perf()")
    public Object log4PerfAround(ProceedingJoinPoint point) throws Throwable {
        return perfLog(point);
    }


    @Override
    public AppCoordinate appCoordinate() {
        return paymentProperties;
    }
}
